package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.UserMapper;
import com.fs.pojo.User;
import com.fs.pojo.WhInvInventory;
import com.fs.service.UserService;
import com.fs.vo.Condition;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author hyy
 * @version 1.0
 * @description: 用户服务类实现
 * @date 2024/10/14 10:59
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> queryUsers(User user) {
        LambdaQueryWrapper<User> queryWrapper = null;
        if (user != null && user.getUserName() != null) {
            queryWrapper = new LambdaQueryWrapper<User>()
                    .eq(User::getUserName, user.getUserName());
        }
        return userMapper.selectList(queryWrapper);
    }

    /**
     * 查询经理
     *
     * @return
     */
    @Override
    public List<User> findApprover() {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUserType, "经理");
        return userMapper.selectList(wrapper);
    }

    @Override
    public Page<User> querySales(Condition<User> condition) {
        Page<User> page = new Page<>(condition.getPage(), condition.getCount());
        //构建条件构造器
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>();
        wrapper.eq(User::getDeptId, 1001);
        User user = condition.getSearch();
        if (Objects.nonNull(user)) {
            //供应商姓名模糊查询条件
            wrapper.like(user.getUserName() != null, User::getUserName, user.getUserName())
                    //编号查询
                    .eq(user.getUserId() != null, User::getUserId, user.getUserId())

                    .eq(user.getStatus() != null, User::getStatus, user.getStatus());
        }
        return userMapper.selectPage(page, wrapper);
    }

    @Override
    public List<User> queryStorage() {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getDeptId, 1003);
        return userMapper.selectList(wrapper);
    }

//    @Override
//    public List<User> selectAll(Condition<User> condition) {
//
//        return userMapper.selectAll();
//    }

    @Override
    public PageInfo<User> selectAll(Condition<User> condition) {
        System.out.println(condition.getSearch());
        PageHelper.startPage(condition.getPage(), condition.getCount());
        List<User> User = userMapper.selectAll(condition.getSearch());
        return new PageInfo<>(User);
    }

    @Override
    public void deleteById(int userId) {
        userMapper.deleteById(userId);
    }

    @Override
    public User queryById(int userid) {
        return userMapper.queryById(userid);
    }

    @Override
    public void updata(User user) {
        userMapper.updateById(user);
    }
}
